﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Blog.Models.UserServices
{
    public class UserRepository:IUserRepository
    {
        private DataDataContext db = new DataDataContext();
        public IQueryable<User> FindAlldata()
        {
            return db.Users;
        }

        public User GetByIdMax()
        {
            throw new System.NotImplementedException();
        }

        public User Getdata(int id)
        {
            return (from c in db.Users
                    where c.UserId == id
                    select c).FirstOrDefault();
        }

        public User GetDataByName(string name)
        {
            return (from x in db.Users
                     where x.UserName == name
                     select x).FirstOrDefault();
        }

        public void Add(User data)
        {
            db.Users.InsertOnSubmit(data);
        }

        public void Delete(User data)
        {
            db.Users.DeleteOnSubmit(data);
        }

        public void Save()
        {
            db.SubmitChanges();
        }
    }
}
